<template>
  <div>
    <div id="ecgView">
      <svg id="ecg" width="1027" height="500"></svg>
    </div>
  </div>
</template>

<script>
import * as Ecg from './ecg'
export default {
  name: 'EcgChart1',
  props: {
    ecgvalue: {
      type: Array,
      default: undefined
    },
    headerData: {
      type: Object,
      default: undefined,
    }
  },
  data() {
    return {
      parentDiv: [],
      start_time: 1509360664,
      sample: 200,
      ecgData: undefined
    }
  },
  watch: {
    'ecgvalue': 'fetchData'
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      let res = this.ecgvalue
      this.ecgData = res.map(item => {return item - 2048})
      this.$nextTick(() => {
        this.showEcg()
        this.showEcgByData()
      })
    },
    showEcg() {
      const oEcg = document.getElementById('ecg')
      this.parentDiv.push('ecgView')
      Ecg.Ecg.init(oEcg, this.parentDiv)
      Ecg.Ecg.draw(this.headerData, this.ecgData, this.start_time, this.sample)
    },
    showEcgByData() {
      const oEcg = document.getElementById('ecg')
      var ecgDataArray = this.ecgData
      // .split('\n')
      // this.sample = ecgDataArray[1]
      // this.headerData.report_id = '报告编号：' + ecgDataArray[0]
      // ecgDataArray.shift()
      // ecgDataArray.shift()
      Ecg.Ecg.init(oEcg, this.parentDiv)
      Ecg.Ecg.draw(this.headerData, ecgDataArray, this.start_time, this.sample)
    }
  }
}
</script>

<style lang="scss">

</style>
